drop table test;

CREATE TABLE test as (select box(point(x, x),point(x, x)) 
	from generate_series(1,500000) as x);

CREATE INDEX test_idx ON test USING gist (box);

SET enable_seqscan TO false;
SET enable_bitmapscan TO false;
SET enable_indexscan TO true;
SET enable_indexonlyscan TO true;

select pg_size_pretty(pg_relation_size('test_idx'));

delete from test where box && box(point(0,0), point(500000,500000));
select pg_size_pretty(pg_relation_size('test_idx'));

-- This query invokes gistkillitems()
select box from test where box && box(point(0,0), point(500000,500000));

insert into test (select box(point(x, x),point(x, x)) 
	from generate_series(1,500000) as x);

select pg_size_pretty(pg_relation_size('test_idx'));

insert into test (select box(point(x, x),point(x, x)) 
	from generate_series(1,500000) as x);

select pg_size_pretty(pg_relation_size('test_idx'));

insert into test (select box(point(x, x),point(x, x)) 
	from generate_series(1,500000) as x);

select pg_size_pretty(pg_relation_size('test_idx'));
